import React from 'react'
import ReactDOM from 'react-dom'

class App extends React.Component{
    state = {
        number: 0
    }

    handleClick = () => {
        this.setState(() => {
            return {
                number: Math.floor(Math.random() * 3)
            }
        })
    }

    // render方法调用并不意味着浏览器中的重新渲染
    // render方法调用仅仅声明要进行diff
    render() {
        const e1 = (
            <div>
                <h1>随机数：</h1>
                <p>{this.state.number}</p>
                <button onClick={this.handleClick}>重新生成</button>
            </div>
        )
        console.log(e1)
        return e1
    }
}

ReactDOM.render(<App />, document.getElementById('root'))